home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / adaed-1.11 / adaed-1 / Adaed-1.11.0a / axqr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-07  |  6.3 KB  |  235 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9.  
  10. /* procedures for reading axq files.
  11.  * Since these are used by the interpreter, it is ESSENTIAL that
  12.  * neither hdr.h or ghdr.h be required for their compilation.
  13.  */
  14.  
  15. #include "config.h"
  16. #include <stdio.h>
  17. #include "ifile.h"
  18. #include "segment.h"
  19. #include "slot.h"
  20. #include "stdlib.h"
  21. #include "libfprots.h"
  22. #include "miscprots.h"
  23. #include "axqrprots.h"
  24.  
  25. static Slot *get_slot(IFILE *, int, int *);
  26.  
  27. /* define DEBUG to include print statments that are always done */
  28.  
  29. #ifdef DEBUG
  30. #define IOT
  31. #endif
  32.  
  33. #ifdef IOT
  34. extern int iot_ifile;
  35. #endif
  36.  
  37. Segment segment_new(int kind, int initdim)        /*;segment_new*/
  38. {
  39.     Segment    s;
  40.  
  41.     s = (Segment) emalloct(sizeof(Segment_s), "segment-new");
  42.     s->seg_kind = kind;
  43.     s->seg_ptr = (int **) 0;
  44.     if (kind==SEGMENT_KIND_CODE) {
  45.         s->seg_size = sizeof(char);
  46.         if (initdim==0) initdim = 128;
  47.         s->seg_dim = initdim;
  48.         s->seg_extend = 128;
  49.     }
  50.     else {
  51.         s->seg_size = sizeof(int);
  52.         if (initdim==0) initdim = 32; /* initial dimension */
  53.         s->seg_dim = initdim;
  54.         s->seg_extend = 8;
  55.     }
  56.     s->seg_pos = 0;
  57.     s->seg_maxpos = 0;
  58.     s->seg_data = emalloct(s->seg_dim * s->seg_size, "segment-data");
  59.     s->seg_id = SEG_ID;        /* insert value to check segment validity*/
  60.     return s;
  61. }
  62.  
  63. Segment segment_read(IFILE *file)                /*;segment_read*/
  64. {
  65.     Segment    seg;
  66.     short    dim;
  67.     int        kind;
  68.     kind = getnum(file,"segment-kind");
  69.     dim = getnum(file,"segment-dim");
  70.     seg = segment_new(kind, dim);
  71. #ifdef HI_LEVEL_IO
  72.     fread(seg->seg_data,seg->seg_size,dim,file->fh_file);
  73. #else
  74.     read(file->fh_file,seg->seg_data,seg->seg_size*dim);
  75. #endif
  76.     seg->seg_maxpos = dim - 1;
  77.     return seg;
  78. }
  79.  
  80. void read_axq(IFILE *axq_file, Axq axq)                            /*;read_axq*/
  81. {
  82.     /* axq has been set with loads an AXQ */
  83.  
  84.     Segment    newseg,segment_get();
  85.     int        si,snum,nsegs,sj;
  86.     char    **get_axq_slots();
  87.     char    *funame,*u_type;
  88.     long    genpos,rec;
  89.  
  90. #ifdef TBSL
  91.     if (debug_trace) {
  92.         TO_ERRFILE("reading axq ",  axq_file_name) ;
  93.     }
  94.     efclose(axq_file);
  95. #endif
  96.     for (rec=read_init(axq_file); rec != 0; rec=read_next(axq_file,rec)) {
  97.         funame = getstr(axq_file,"axq-unit-name");
  98.         getnum(axq_file,"axq-num");
  99.         u_type = unit_name_type(funame);
  100.         /* In the C version, DATA_SLOTS CODE_SLOTS and EXCEPTION_SLOTS are at
  101.          * the end of the file, and are read below
  102.          */
  103.         /* load subprogram bodies, package specs and bodies and main unit */
  104.         if (!(streq(u_type,"su") || streq(u_type,"sp") || streq(u_type,"bo")
  105.           || streq(u_type,"ma"))) {
  106.             continue; /* skip other units */
  107.         }
  108.         genpos = getlong(axq_file,"axq-gen-pos");
  109.         /* position to start of generator info */
  110.         ifseek(axq_file, "axq-gen_info", genpos, 0);
  111.         for (si=0;si<4;si++) {
  112.             nsegs = getnum(axq_file,"number-segments");
  113.             for (sj=1;sj<=nsegs;sj++) {
  114.                 snum = getnum(axq_file,"axq-segment-num");
  115.                 newseg = segment_read(axq_file);
  116.                 if (newseg->seg_kind==SEGMENT_KIND_CODE) {
  117.                     if (snum>=axq->axq_code_segments_dim)  {
  118. #ifdef IOT
  119.                         if(axq_file->fh_trace) {
  120.                             printf("snum %d dim %d\n",snum,
  121.                               axq->axq_code_segments_dim);
  122.                         }
  123. #endif
  124.                         chaos("code_segment_number error");
  125.                     }
  126.                     axq->axq_code_segments[snum] = newseg->seg_data;
  127.                     axq->axq_code_seglen[snum] = newseg->seg_dim;
  128.                 }
  129.                 if (newseg->seg_kind==SEGMENT_KIND_DATA) {
  130.                     if (snum>=axq->axq_data_segments_dim)  {
  131. #ifdef IOT
  132.                         if (axq_file->fh_trace) {
  133.                             printf("snum %d dim %d\n",snum,
  134.                               axq->axq_data_segments_dim);
  135.                         }
  136. #endif
  137.                         chaos("data_segment number too big");
  138.                     }
  139.                     axq->axq_data_segments[snum] = (int *) newseg->seg_data;
  140.                     axq->axq_data_seglen[snum] = newseg->seg_dim;
  141.                 }
  142.             }
  143.         }
  144.     }
  145. #ifdef TBSL
  146. else {
  147.     TO_LIST("*** Unable to read AXQfile ",axq_file_name);
  148.     stop;
  149. }
  150. #endif
  151. }
  152.  
  153. long get_cde_slots(IFILE *file, Axq axq)                    /*;get_cde_slots*/
  154. {
  155.     /* get slots info from file. The offset within the file is not changed */
  156.  
  157.     long    dpos,start_pos;
  158.     int        n_code,n_data,n_exception,dim;
  159.  
  160.     start_pos = iftell(file); /* save pos so can restore after reading slots*/
  161.     dpos = file->fh_slots;/* get offset for slots */
  162.     if (dpos==0l)
  163.         chaos("get_cde_slots: slot offset zero");
  164.     ifseek(file,"slots-start",dpos,0);/* position to start of slot info */
  165.     n_code = getnum(file,"n-code");
  166.     n_data = getnum(file,"n-data");
  167.     n_exception = getnum(file,"n-exception");
  168.     axq->axq_code_slots_dim = n_code + 1;
  169.     axq->axq_code_slots = get_slot(file,n_code,&dim);
  170.     axq->axq_code_segments_dim = dim;
  171.     axq->axq_data_slots_dim = n_data + 1;
  172.     axq->axq_data_slots = get_slot(file,n_data,&dim);
  173.     axq->axq_data_segments_dim = dim;
  174.     axq->axq_exception_slots_dim = n_exception + 1;
  175.     axq->axq_exception_slots = get_slot(file,n_exception,&dim);
  176.     axq->axq_exception_slots_dim = dim;
  177. #ifdef IOT
  178.     if (file->fh_trace) {
  179.         printf("slots dims code %d data %d exception %d\n", /* DEBUG */
  180.           axq->axq_code_slots_dim, axq->axq_data_slots_dim,
  181.           axq->axq_exception_slots_dim);
  182.         printf("code_segments_dim %d data_segments_dim %d\n", /* DEBUG */
  183.           axq->axq_code_segments_dim, axq->axq_data_segments_dim);
  184.     }
  185. #endif
  186.     ifseek(file,"slots-reset",start_pos,0);/* restore position */
  187.     return dpos; /* return offset of start of slot info */
  188. }
  189.  
  190. static Slot *get_slot(IFILE *file, int nmax, int *dim)            /*;get_slot*/
  191. {
  192.     /* This procedure reads in the SLOTS information. 
  193.      * Entries are Slots structures. nmax is guess at needed dimension,
  194.      * dim is set to dimension actually found.
  195.      */
  196.  
  197.     int i,n,exists;
  198.     Slot    *tup;
  199.     Slot    slot;
  200.  
  201.     *dim = nmax+1;
  202.     tup = (Slot *) emalloct((unsigned)*dim * sizeof(Slot), "get-slot");
  203.     n  = getnum(file,"slot-entries");
  204. #ifdef IOT
  205.     if (file->fh_trace)
  206.         printf("get_slot initial dim %d entries %d\n",*dim,n); /*DEBUG*/
  207. #endif
  208.     for (i = 1; i <= n; i++) {
  209.         exists = getnum(file,"slot-exists");
  210.         if (exists) {
  211.             slot = (Slot) emalloct(sizeof(Slot_s), "get-slot-1");
  212.             slot->slot_seq = getnum(file,"slot-seq");
  213.             slot->slot_unit = getnum(file,"slot-unit");
  214.             slot->slot_number = getnum(file,"slot-number");
  215.             slot->slot_name = getstr(file,"slot_name");
  216.             if (slot->slot_number >= *dim) {
  217.                 *dim = slot->slot_number + 1;
  218. #ifdef IOT
  219.                 if (file->fh_trace)
  220.                     printf("expanding dim to %d\n",*dim); /* DEBUG */
  221. #endif
  222.             }
  223. #ifdef IOT
  224.             if (file->fh_trace)
  225.                 printf("reading entry %d slot number %d\n",i,slot->slot_number);
  226. #endif
  227.             tup[i] =  slot;
  228.         }
  229.         else {
  230.             tup[i] = (Slot)0;
  231.         }
  232.     }
  233.     return tup;
  234. }
  235.